﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PhoneStore.Entity;

namespace PhoneStore.Presentation.CompositeControl
{
    /// <summary>
    /// Interaction logic for CustomerListTab.xaml
    /// </summary>
    public partial class CustomerListTab : BaseUserControl
    {
        public CustomerListTab()
        {
            InitializeComponent();
            ucList.SetUp(EnableEditItemFunc, true, CheckError);
        }

        public string CheckError()
        {
            string errors = "";
            if (String.IsNullOrEmpty(txtFullName.Text))
            {
                errors += "-Tên nhân viên không được trống\n";
            }
            if (cbbType.SelectedItem == null)
            {
                errors += "-Loại khách hàng không được trống\n";
            }

            return errors;
        }

        protected override void SetUpComboBox()
        {
            cbbType.ItemsSource = DAO.GetAll<Kind>().Select(x => new {Value=x.KindID,Text=x.Description});
            cbbType.SelectedValuePath = "Value";
            cbbType.DisplayMemberPath = "Text";
        }

        protected override void EnableEditItemFunc(bool value)
        {
            txtAddress.IsEnabled = txtFullName.IsEnabled = txtPhone.IsEnabled =
                cbbType.IsEnabled = dpDOB.IsEnabled = value;
        }
    }
}
